﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;
using JumbotCms.Common;
namespace JumbotCms.WebFile.Admin
{
    public partial class _pagedittemplate : JumbotCms.API.AdminCenter
    {
        public string tpPath = string.Empty;
        private string _Source = string.Empty;
        private string _tempFile = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            Admin_Load("0000", "html");
            id = Str2Str(q("id"));
            string sid = Str2Str(q("sid"));

            doh.Reset();
            doh.ConditionExpress = "id=@id";
            doh.AddConditionParameter("@id", sid);
            tpPath = doh.GetValue("jcms_normal_page_sort", "Dir").ToString();
            if (tpPath.Length == 0)
            {
                Response.Write("单页分组选择有误!");
                Response.End();
                return;
            }
            JumbotCms.DataObject.Page sPage = new JumbotCms.DataObject.Page();
            _Source = sPage.GetSource(id, doh);
            _tempFile = site.Dir + "_data/page/" + tpPath + "_" + _Source;
            if (!IsPostBack)
            {
                if (Jumbot.Common.DirFile.FileExists(_tempFile))
                    this.txtTemplateContent.Text = Jumbot.Common.DirFile.ReadFile(_tempFile);
                else
                    this.txtTemplateContent.Text = "";
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string PageStr = this.txtTemplateContent.Text;
            Jumbot.Common.DirFile.SaveFile(PageStr, _tempFile);
            FinalMessage("成功保存", site.Dir + "admin/close.htm", 0);
        }
    }
}
